<?php
    $xtpl_edit      = new XTemplate("view/customer/edit.htm");
    $id             = $_GET['id'];
    
    $title  = "Sửa thông tin khách hàng";
    
    $query  = "SELECT * FROM customer WHERE id_c='" . $id ."'";
    $re     = mysql_query($query);
    $row    = mysql_fetch_array($re);
    
    $xtpl_edit  -> assign('fullname', $row['fullname']);
    $xtpl_edit  -> assign('email', $row['email']);
    $xtpl_edit  -> assign('address', $row['address']);
    $xtpl_edit  -> assign('phone', $row['phone']);
    
    if(isset($_POST['submit'])){
        if(($_POST['fullname']!=NULL)&&($_POST['email']!=NULL)&&($_POST['address']!=NULL)&&($_POST['phone']!=NULL)){
            $sql    = "UPDATE customer SET fullname='" . $_POST['fullname'] . "', email='". $_POST['email'] . "', address='" . $_POST['address'] . "', phone='" . $_POST['phone'] . "' WHERE id_c='" . $id . "'";
            $result = mysql_query($sql);
            if($result){
                $error="Đã sửa thông tin khách hàng";
            }
        }
        else{
            $error="Bạn chưa điền đầy đủ thông tin";
        }
    }
    
    if(isset($_POST['cancel'])){
        header("location:index.php?page=customer");
    }
    
    $xtpl_edit      -> assign('error', $error);
    $xtpl_edit      -> parse("EDIT");
    $content        = $xtpl_edit -> text("EDIT");
?>